<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>资料详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
        rel="stylesheet" />
    <script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>>

    <style>
        html {
            height: 100%;
        }

        body {
            height: 100%;
        }

        .left {
            width: 50%;
            padding: 10px 0px;
            display: flex;
            flex-direction: column;
        }

        .left-cont {
            padding: 0 10px;
        }

        .page-cont {
            height: 100%;
            background-color: #ffffff;
            display: flex;
        }

        .right {
            width: 50%;
            padding: 10px 0px;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .right-cont {
            border-left: 2px solid #EEEEEE;
            padding: 0 10px;
            overflow-y: scroll;
            height: 100%;
        }

        .title {
            font-size: 18px;
            font-weight: bold;
            line-height: 30px;
        }

        .user-info {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            font-size: 14px;
            line-height: 26px;
        }

        .user-lab {
            display: flex;
            width: 33.33%;
        }

        .zlbox {
            flex: 1;
            display: flex;
            justify-content: space-around;
            font-size: 16px;
            line-height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .line {
            border-top: 1px solid #eeeeee;
            /*  margin: 10px 0px;*/
        }

        .box-left {
            width: 30%;
            border: 1px solid #eeeeee;
            /*        padding: 5px;*/
            overflow-y: auto;
            background-color: #f5f5f5;
        }

        .box-right {
            width: 65%;
            border: 1px solid #eeeeee;
            padding: 5px;
            overflow-y: auto;
        }

        .right-row {
            padding-top: 10px;
            display: flex;
        }

        .right-row-lab {
            width: 70px;
        }

        .right-row-input {
            flex: 1;
        }

        .layui-textarea {
            min-height: 70px !important;
        }

        .addbtn {
            height: 30px;
            line-height: 30px;
            text-align: center;
            /*        background-color:#1beded*/
        }

        .iconDianosis .layui-tab-title {
            border-bottom: none;
            flex-wrap: wrap;
            display: flex;
            height: auto;
        }

        .layui-tab-title .layui-this:after {
            border-width: 0px;
            pointer-events: none;
        }

        .layui-tab-title li {
            background: #f6f6f6;
            margin: 4px 20px 4px 0;
            word-wrap: break-word;
            word-break: break-all;
        }

        .iconDianosis .layui-tab-title li .layui-tab-close {
            border-radius: 50%;
        }

        #left-file-cont .sele {
            background-color: #ffffff;
            color: #2384e2;
            border-right-color: #ffffff;
        }

        #left-file-cont li {
            cursor: pointer;
            padding: 5px 10px;
            border: 1px solid #eeeeee;
        }

        .imgflex {
            display: flex;
            flex-wrap: wrap;
            width: 100%;
            align-items: center;
        }

        .bofang {
            position: absolute;
            top: 0;
            left: 0
        }

        .img {
            margin: 10px;
            width: 80px;
            height: 80px;
        }

        .right-file-cont {
            padding: 5px;
        }

        .imgPreview {
            height: 100%;
            width: 100%;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: auto;
        }

        .imgtop {
            display: flex;
            justify-content: center;
            position: fixed;
            left: 190px;
            bottom: 70px;
            opacity: 0.6;
            width: 400px;
            z-index: 4;
        }

        .imgcont {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .btndiv {
            display: flex;
            float: left;
            flex-direction: column;
            align-items: center;
            width: 60px;
            height: 60px;
            background-color: #ffffff;
            border-radius: 30px;
            justify-content: center;
            opacity: 0.8;
        }

        .tabsel {
            padding: 10px 0;
            display: flex;
        }

        .tabselDiv {
            padding: 8px;
            border: 1px solid #eeeeee;
            font-size: 18px;
            cursor: pointer;
        }

        .seldiv {
            color: #2384e2;
        }

        .ocrContent {
            overflow-y: auto;
            position: relative;
            box-sizing: border-box;
        }

        .ocrImgDiv {
            float: right;
            cursor: pointer;
        }

        .ocrImg {
            height: 80px;
            width: 80px;
        }

        .ocrtxt {
            padding-bottom: 50px;
        }

        .ocrtips {
            position: fixed;
            bottom: 0;
            height: 50px;
            right: 53%;
            text-align: center;
            z-index: 99;
        }

        .nexttxt {
            border: 1px solid #eeeeee;
            background-color: #ffffff;
            padding: 10px;
            cursor: pointer;
        }

        .lineEmpty {
            width: 10px;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="layui-fluid box">
        <div class="page-cont layui-form">
            <div class="left" id="zlinfo">
                <div class="left-cont" id="patView">

                </div>
                <div class="zlbox">
                    <div class="box-left">
                        <div id="left-file-cont">
                        </div>
                    </div>
                    <div class="box-right">
                        <div class="right-file-cont" id="right-file-cont"></div>
                    </div>
                </div>
            </div>
            <div class="right" id="medInfo">
                <div class="right-cont">
                    <div id="patMedView">

                    </div>
                    <div class="right-row">
                        <div class="right-row-lab">主诉：</div>
                        <div class="right-row-input">
                            <textarea id="Symptoms" disabled class="layui-textarea" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="right-row">
                        <div class="right-row-lab">现病史：</div>
                        <div class="right-row-input">
                            <textarea id="SicknessHistory" disabled class="layui-textarea" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="right-row">
                        <div class="right-row-lab">体格检查：</div>
                        <div class="right-row-input">
                            <textarea id="PhysicalExam" disabled class="layui-textarea" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="right-row">
                        <div class="right-row-lab">辅助检查：</div>
                        <div class="right-row-input">
                            <textarea id="AuxiliaryExam" disabled class="layui-textarea" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="right-row">
                        <div class="right-row-lab">诊断：</div>
                    </div>
                    <div id="diagnosView" class="iconDianosis">

                    </div>
                    <div class="right-row">
                        <div class="right-row-lab">指导建议：</div>
                        <div class="right-row-input" style="display:flex">
                            <input type="checkbox" disabled id="yzfilter" value="按医嘱服药" lay-filter="yzfilter"
                                title="按医嘱服药" lay-skin="primary">
                            <input type="checkbox" disabled id="yzfilter" value="进行心脏康复治疗" lay-filter="yzfilter"
                                title="进行心脏康复治疗" lay-skin="primary">
                            <input type="checkbox" disabled value="其他" lay-filter="yzfilter" id="yzfilter" title="其他"
                                lay-skin="primary">


                        </div>
                    </div>
                    <input type="text" disabled class="layui-input" style="display:none;margin-top:10px" id="other" />

                    <div id="shyj">

                    </div>

                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script>
    layui.config({
        base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    });

    layui.define(['index', 'layer', 'form', 'element', 'table', 'upload', 'laytpl'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var table = layui.table;
        var $ = layui.$;
        var admin = layui.admin;
        var setter = layui.setter;
        var upload = layui.upload;
        var laytpl = layui.laytpl;


        var controller = { 
            //参数
            data: {
                model: null,
                medInfo: {},//病历
                patInfo: {},//病人信息
                diagnosisList: [],//诊断列表
                fileList: [],//资料内容【包含项目】
                fileHeadList: [],//资料项目
                questList: [],//问卷
                Symptoms: "",//主术
                SicknessHistory: "",//现病史
                PhysicalExam: "",//体格检查
                AuxiliaryExam: "",//辅助检查
                DocAdvise: "",//医生建议
                Status: 0,//审核状态 1通过 2不通过
                EditText: '',//审核内容          
                currentIndex: 0,//当前选择项
                tabIndex: 0,//0:图片1:OCR
                tablist: [],//识别list
                ocrIndex: 0,//第几张
                imglist: [],
                imgindex: 0,
                current: 0,//旋转角度
                type: false,//横向纵向标识，用于重设高度,false为横向
                targetimg: $('#targetimg'),//图片
                imgdiv: $('#imgdiv'),//图片所在div
                wdwwth: 0,
                hewwth: 0,
                imgheight: 0,
                imgwidth: 0,
            },
          
            //初始化
            init: function () {
                var self = this;
                this.data.model = parent.currData;
                this.getList(this.data.model.RecordId).then(res => {
                    console.log(res);
                    this.data.patInfo = res.data.patInfo;
                    if (this.data.patInfo.Weight > 0 && this.data.patInfo.Height > 0) {
                        var a = parseFloat(this.data.patInfo.Height * this.data.patInfo.Height * 0.0001);
                        this.data.patInfo.BMI = parseFloat(this.data.patInfo.Weight / a).toFixed(1);
                    } else {
                        this.data.patInfo.BMI = 0;
                    }
                    this.data.patInfo.Age = this.GetAgeByIdCard(this.data.patInfo.IDCard);
                    this.data.patInfo.BirthDay = this.GetBirthDayByIdCard(this.data.patInfo.IDCard);
                    this.data.medInfo = (res.data.medInfo && res.data.medInfo != "null") ? res.data.medInfo : {};
                    this.data.diagnosisList = res.data.diagnosis;
                    this.data.fileList = res.data.fileList;
                    this.data.fileHeadList = res.data.fileHeadList;
                    this.data.questList = res.data.questList;
                    if (this.data.questList.length > 0) {
                        this.data.questList.forEach((item, index) => {
                            if (item.ATitle) {
                                var arry = JSON.parse(item.ATitle);
                                var tt = arry.map(res => {
                                    return res.title;
                                }).join(",");
                                item.ATitle = tt;
                            }

                        })
                    }
                    this.data.fileHeadList.forEach(res => {
                        if (res.Type == 2 || res.Type == 3) {
                            res.Count = this.data.fileList.filter((item, index) => {
                                return res.ItemId == item.ItemId;
                            }).length;
                        }
                    })
                    this.patView();
                    this.diagnosView();
                    this.fileHeadView();
                    this.medView();
                    this.shyjView();
                    this.pageEvent();
                }).catch(res = {
                });
                parent.getResult = function () {
                    var adcheck = [];
                    $('input[type=checkbox]:checked').each(function () {
                        adcheck.push($(this).val());
                    });
                    self.data.medInfo.DocAdvise = adcheck.join(",");
                    if (self.data.medInfo.DocAdvise.indexOf("其他") > -1) {
                        self.data.medInfo.DocAdvise += ":" + $("#other").val();
                    }
                    self.data.medInfo.Symptoms = $("#Symptoms").val();
                    self.data.medInfo.SicknessHistory = $("#SicknessHistory").val();
                    self.data.medInfo.PhysicalExam = $("#PhysicalExam").val();
                    self.data.medInfo.AuxiliaryExam = $("#AuxiliaryExam").val();
                    self.data.medInfo.EditText = $("#Remark").val();
                    var data = {
                        medInfo: self.data.medInfo,
                        PatListId: self.data.patInfo.PatlistId,
                        diagnosisList: self.data.diagnosisList,
                        Status: self.data.Status,
                        FileId: self.data.model.FileId,
                        EditText: self.data.EditText,
                    }
                    this.console.log(data);
                    return data;
                }
            },
            /***病历 */
            medView: function () {
                if (this.data.medInfo && this.data.medInfo.MedicalRecordID > 0) {
                    $("#Symptoms").val(this.data.medInfo.Symptoms);
                    $("#SicknessHistory").val(this.data.medInfo.SicknessHistory);
                    $("#PhysicalExam").val(this.data.medInfo.PhysicalExam);
                    $("#AuxiliaryExam").val(this.data.medInfo.AuxiliaryExam);
                    var checkBox = $("input[id='yzfilter']");
                    for (var i = 0; i < checkBox.length; i++) {
                        if (this.data.medInfo.DocAdvise && this.data.medInfo.DocAdvise.indexOf(checkBox[i].title) > -1) {
                            checkBox[i].checked = true;
                        }
                    }
                    if (this.data.medInfo.DocAdvise && this.data.medInfo.DocAdvise.indexOf("其他") > -1) {
                        $("#other").show();
                        $("#other").val(this.data.medInfo.DocAdvise.split(":")[1]);
                    }
                    form.render();
                }
            },

            /***
             * 审核意见
             * */
            shyjView: function () {
                var self = this;
                if (this.data.patInfo.FileId && this.data.patInfo.FileId > 0) {
                    var shyjView = document.getElementById('shyj');
                    var getTpl1 = shyjTem.innerHTML;
                    laytpl(getTpl1).render({ AuditStatus: this.data.patInfo.AuditStatus, AuditTxt: this.data.patInfo.AuditTxt }, function (html) {
                        shyjView.innerHTML = html;
                        form.render();
                    });
                }
            },

            /***展示资料项目 */
            fileHeadView: function () {
                var self = this;
                if (self.data.fileHeadList.length > 0) {
                    var fileheadView = document.getElementById('left-file-cont');
                    var getTpl1 = fileHeadTemp.innerHTML;
                    laytpl(getTpl1).render({ data: this.data.fileHeadList, currentIndex: this.data.currentIndex }, function (html) {
                        fileheadView.innerHTML = html;
                        form.render();
                    });
                }
                if (self.data.tabIndex == 0) {
                    self.fileView();
                } else {
                    self.data.ocrIndex = 0;
                    self.fileOCR();
                }
            },
            /***
            * OCR图片放大
            * */
            prewOCRImg() {
                var joson = {
                    "title": "", //相册标题
                    "id": 123, //相册id
                    "start": 0, //初始显示的图片序号，默认0
                    "data": [   //相册包含的图片，数组格式
                        {
                            "alt": "",
                            "pid": 666, //图片id
                            "src": this.data.tablist[this.data.ocrIndex].FileUrl, //原图地址
                            "thumb": "" //缩略图地址
                        }
                    ]
                }
                layer.photos({
                    photos: joson,
                    shadeclose: false,
                    closebtn: 2,
                    anim: 0
                });
            },
            /**
             * 解析识别内容
             * @param {any} str
             */
            splitRequestContent(str) {
                var list = [];
                var relist = [];
                relist = JSON.parse(str);
                var model = {};
                var flowY = 0;//Y坐标，根据Y坐标是否换行
                relist.forEach((item, index) => {
                    if (item.DetectedText) {
                        if (flowY > 0) {
                            if (flowY > item.ItemPolygon.Y - 15 && flowY < item.ItemPolygon.Y + 15) {
                                flowY = item.ItemPolygon.Y;
                                model.Text += "<text class=\"lineEmpty\"></text>" + item.DetectedText;
                            } else {
                                model.Y = flowY;
                                list.push(model);
                                model = {};
                                model.Text = item.DetectedText;
                                flowY = item.ItemPolygon.Y;
                            }
                        } else {//首次循环
                            flowY = item.ItemPolygon.Y;
                            model.Text = item.DetectedText;
                        }
                        if (relist.length - 1 == index) {//只有一行,最后一行
                            model.Y = flowY;
                            list.push(model);
                        }
                    }
                });
                return list;
            },
            /****
             * 显示OCR
             * */
            fileOCR: function () {
                var self = this;
                this.data.tablist = [];
                var model = this.data.fileHeadList[this.data.currentIndex];
                if (!model) {
                    return;
                }
                if (model.Type == 2 || model.Type == 3) {
                    this.data.tablist = this.data.fileList.filter(res => {
                        return res.ItemId == model.ItemId && res.Id > 0;
                    })
                }
                this.data.tablist.forEach((item, index) => {
                    if (item.RequestContent) {

                    }
                })
                var fileView = document.getElementById('right-file-cont');
                fileView.innerHTML = "";
                var getTpl1 = fileOCRTemp.innerHTML;
                var modelinfo = null;
                if (this.data.tablist.length > 0) {
                    modelinfo = this.data.tablist[this.data.ocrIndex];
                    if (modelinfo.RequestContent) {
                        modelinfo.list = this.splitRequestContent(modelinfo.RequestContent);
                    }
                }

                laytpl(getTpl1).render({ model: modelinfo, Count: this.data.tablist.length }, function (html) {
                    fileView.innerHTML = html;
                    form.render();
                });
                $('#ocrImgDiv').on('click', function (e) {
                    self.prewOCRImg();
                });
            },
            /***
             *展示资料内容 
             * */
            fileView: function () {
                var self = this;
                var list = [];
                var model = this.data.fileHeadList[this.data.currentIndex];
                if (!model) {
                    return;
                }
                if (model.Type == 1) {
                    list = this.data.questList.filter(res => {
                        return res.ItemId == model.ItemId;
                    })
                }
                if (model.Type == 2 || model.Type == 3) {
                    list = this.data.fileList.filter(res => {
                        return res.ItemId == model.ItemId;
                    })
                }
                var fileView = document.getElementById('right-file-cont');
                fileView.innerHTML = "";
                var getTpl1 = fileTemp.innerHTML;
                laytpl(getTpl1).render({ list: list, model: model }, function (html) {
                    fileView.innerHTML = html;
                    form.render();
                });
                $('#right-file-cont .img').on('click', function (e) {
                    console.log(e);
                    var type = e.target.dataset.type;
                    if (type == 0) {
                        self.data.imgindex = parseInt(e.target.dataset.index);

                        self.data.imglist = self.data.fileList.filter(res => {
                            return res.ItemId == model.ItemId && res.Type == 0;
                        });
                        console.log(self.data.imglist);
                        self.previewImg();
                        self.initevent();
                    } else if (type == 1) {
                        window.open(e.target.dataset.fileurl, "_blank");
                    }
                })
            },
            previewImg(obj) {
                var self = this;
                var img = new Image();
                console.log(self.data.imglist[self.data.imgindex]);
                img.src = self.data.imglist[self.data.imgindex].FileUrl;
                var imgHtml = $("#imgPreview");
                var imgpre = $("#imgdiv");
                imgpre.empty();
                imgpre.append("<img  src='" + img.src + "' id='targetimg' />")
                //弹出层
                layer.open({
                    type: 1,
                    shade: 0,
                    id: 'LAY_layuipro',
                    offset: ['0px', '0px'],
                    closeBtn: 0,
                    btn: ['关闭'],
                    //zIndex:3,
                    area: ['50%', '100%'],
                    //shadeClose: true,//点击外围关闭弹窗
                    // scrollbar: true,//不现实滚动条
                    title: false, //不显示标题
                    content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                    cancel: function () {
                        console.log(111)
                        //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
                    }, yes: function (index, layero) {
                        layer.close(index);
                    }, success: function (layero, index) {
                        var bb = $("#LAY_layuipro").width();
                        $("#imgtop").css("left", (bb / 2) - 200);

                    }
                });
                if (this.data.imgheight == 0) {
                    var th = $("#imgPreview").height();
                    if ($('#imgdiv').height() > th) {
                        self.data.imgheight = th;
                    } else {
                        self.data.imgheight = th;
                    }
                }
                if (this.data.imgwidth == 0) {
                    this.data.imgwidth = $("#imgPreview").width();
                }
                $("#imgPreview").height(this.data.imgheight);
                $("#imgPreview").width(this.data.imgwidth);

                if (self.data.wdwwth == 0) {

                    //self.data.wdwwth = $('#imgdiv').width();
                    self.data.wdwwth = $("#imgPreview").width();
                }
                if (self.data.hewwth == 0) {
                    var th = $("#imgPreview").height();
                    if ($('#imgdiv').height() > th) {
                        self.data.hewwth = th;
                    } else {
                        //self.data.hewwth = $('#imgdiv').height();
                        self.data.hewwth = th;
                    }
                }

                if ($("#targetimg").height() > self.data.hewwth) {
                    $("#targetimg").height(self.data.hewwth);
                }
                if ($("#targetimg").width() > self.data.wdwwth) {
                    $("#targetimg").width(self.data.wdwwth);
                }

                console.log($("#targetimg").height());
                $('#imgdiv').width(self.data.wdwwth);
                $('#imgdiv').height(self.data.hewwth);

            },
            initevent: function () {
                var that = this;


            },

            rotate: function (flag) {
                //90度旋转
                if (flag == 1)
                    this.data.current = (this.data.current - 90) % 360;
                else
                    this.data.current = (this.data.current + 90) % 360;

                $('#targetimg').css('transform', 'rotate(' + this.data.current + 'deg)');
            },
            resethgt: function () {
                //重设高度
                if (this.data.type) {
                    $('#imgdiv').height($('#targetimg').width());
                }
                else {
                    $('#imgdiv').height($('#targetimg').height());
                    if ($('#imgdiv').height() > $('#imgPreview').height()) {
                        $('#imgPreview').height($('#imgdiv').height())
                    } else {
                        var a = $('#imgPreview').height() / 1.1;
                        if (a < this.data.imgheight) {
                            $('#imgPreview').height(this.data.imgheight);
                        } else {
                            $('#imgPreview').height(a);
                        }
                        //$('#imgPreview').height(this.data.imgheight);
                    }
                }
            },
            resetwth: function (wth) {
                var that = this;
                //重设宽度
                if (wth > $('#imgdiv').width() || (wth > that.data.wdwwth &&
                    wth < $('#imgdiv').width())) {
                    $('#imgdiv').width(wth)
                    if ($('#imgdiv').width() > $('#imgPreview').width()) {
                        $('#imgPreview').width($('#imgdiv').width())
                    } else {
                        $('#imgPreview').width(this.data.imgwidth);
                    }
                    //$('#imgPreview').width(wth)
                }
                else {
                    $('#imgdiv').width(document.body.offsetWidth * 0.5)
                    $('#imgPreview').width(document.body.offsetWidth * 0.5)
                }
            },
            /**
             * 患者界面加载数据显示
             * */
            patView: function () {
                var patView = document.getElementById('patView');
                var getTpl1 = patInfoTemp.innerHTML;
                laytpl(getTpl1).render(this.data.patInfo, function (html) {
                    patView.innerHTML = html;
                    form.render();
                });
                var patMedView = document.getElementById('patMedView');
                var getTpl2 = patMedInfoTemp.innerHTML;
                laytpl(getTpl2).render(this.data.patInfo, function (html) {
                    patMedView.innerHTML = html;
                    form.render();
                });
            },
            /**显示诊断*/
            diagnosView() {
                if (this.data.diagnosisList.length > 0) {
                    var diagnosView = document.getElementById('diagnosView');
                    var getTpl3 = diagnosTemp.innerHTML;
                    laytpl(getTpl3).render(this.data.diagnosisList, function (html) {
                        diagnosView.innerHTML = html;
                        form.render();
                    });
                }
            },
            pageEvent() {
                var self = this;
                var that = this;
                //右转
                $('#rotatergt').click(function () {
                    that.data.type = !that.data.type;
                    that.rotate(2);
                    that.resethgt();
                })
                //左转
                $('#rotateleft').click(function () {
                    that.data.type = !that.data.type;
                    that.rotate(1);

                    that.resethgt();

                })

                //放大
                $('#bigit').click(function () {

                    if ($('#targetimg').height() * 1.1 > $("#imgPreview").height()) {
                        $("#imgdiv").height($('#targetimg').height() * 1.1)
                    }
                    $('#targetimg').height($('#targetimg').height() * 1.1);
                    that.resetwth($('#targetimg').width() * 1.1);
                    $('#targetimg').width($('#targetimg').width() * 1.1);
                    that.resethgt();
                })
                //缩小
                $('#littleit').click(function () {
                    //if ($('#imgdiv').height() / 1.1 > $("#imgdiv").height()) {
                    //    $("#imgdiv").height($('#imgdiv').height() / 1.1)
                    //}
                    $('#targetimg').height($('#targetimg').height() / 1.1);
                    $('#targetimg').width($('#targetimg').width() / 1.1);
                    that.resetwth($('#targetimg').width());
                    that.resethgt();
                })
                $("#beforImg").click(function () {
                    if (that.data.imgindex == 0) {
                        return;
                    }
                    that.data.imgindex = that.data.imgindex - 1;
                    var imgpre = $("#imgdiv");
                    imgpre.empty();
                    imgpre.append("<img  src='" + that.data.imglist[that.data.imgindex].FileUrl + "' id='targetimg' />")
                    $("#imgPreview").height(that.data.imgheight);
                    $("#imgPreview").width(that.data.imgwidth);
                    if (that.data.wdwwth == 0) {

                        that.data.wdwwth = $('#imgdiv').width();
                    }
                    if (that.data.hewwth == 0) {
                        var th = $("#imgPreview").height();
                        if ($('#imgdiv').height() > th) {
                            that.data.hewwth = th;
                        } else {
                            that.data.hewwth = $('#imgdiv').height();
                        }
                    }

                    if ($("#targetimg").height() > that.data.hewwth) {
                        $("#targetimg").height(that.data.hewwth);
                    }
                    if ($("#targetimg").width() > that.data.wdwwth) {
                        $("#targetimg").width(that.data.wdwwth);
                    }

                    console.log($("#targetimg").height());
                    $('#imgdiv').width(that.data.wdwwth);
                    $('#imgdiv').height(that.data.hewwth);
                })
                $("#nextImg").click(function () {
                    if (that.data.imgindex == (that.data.imglist.length - 1)) {
                        return;
                    }
                    that.data.imgindex = that.data.imgindex + 1;
                    var imgpre = $("#imgdiv");
                    imgpre.empty();
                    imgpre.append("<img  src='" + that.data.imglist[that.data.imgindex].FileUrl + "' id='targetimg' />")
                    $("#imgPreview").height(that.data.imgheight);
                    $("#imgPreview").width(that.data.imgwidth);
                    if (that.data.wdwwth == 0) {

                        that.data.wdwwth = $('#imgdiv').width();
                    }
                    if (that.data.hewwth == 0) {
                        var th = $("#imgPreview").height();
                        if ($('#imgdiv').height() > th) {
                            that.data.hewwth = th;
                        } else {
                            that.data.hewwth = $('#imgdiv').height();
                        }
                    }

                    if ($("#targetimg").height() > that.data.hewwth) {
                        $("#targetimg").height(that.data.hewwth);
                    }
                    if ($("#targetimg").width() > that.data.wdwwth) {
                        $("#targetimg").width(that.data.wdwwth);
                    }

                    console.log($("#targetimg").height());
                    $('#imgdiv').width(that.data.wdwwth);
                    $('#imgdiv').height(that.data.hewwth);
                })
                $(document).on("click", ".tabselDiv", function (e) {
                    self.data.tabIndex = $(e.currentTarget).data("index");
                    $(".tabselDiv").removeClass("seldiv");
                    $(e.currentTarget).addClass("seldiv");
                    if (self.data.tabIndex == 0) {
                        self.fileView();
                    } else {
                        self.data.ocrIndex = 0;
                        self.fileOCR();
                    }
                });
                $(document).on("click", ".nexttxt", function (e) {
                    var type = $(e.currentTarget).data("index");
                    console.log(type);
                    if (type == 0) {//上一张
                        if (self.data.ocrIndex > 0) {
                            self.data.ocrIndex = self.data.ocrIndex - 1;
                            self.fileOCR();
                        }
                    } else {
                        if (self.data.ocrIndex < self.data.tablist.length - 1) {
                            self.data.ocrIndex = self.data.ocrIndex + 1;
                            self.fileOCR();
                        }
                    }
                });

                $(document).on("click", "#left-file-cont li", function (e) {
                    self.data.currentIndex = $(e.currentTarget).data("index");
                    $("#left-file-cont li").removeClass("sele");
                    $(e.currentTarget).addClass("sele");
                    if (self.data.tabIndex == 0) {
                        self.fileView();
                    } else {
                        self.data.ocrIndex = 0;
                        self.fileOCR();
                    }
                });

            },

            /**
             * 获取基本信息、病历、诊断、资料等数据
             * **/
            getList(RecordId) { 
                var url="/lowcode/APP20220607085949108/?fun=assistant.getrecorddetail";
                return new Promise((resolve, reject) => {
                    admin.req({
                        url: url,
                        data: { recordId: RecordId },
                        method: "GET",
                        done: res => {
                            if (res.code == 0) {
                                resolve(res);
                            } else {
                                reject(res);
                            }
                        }
                    })
                })
            },
            //计算周岁
            GetAgeByBirthDay(birthday) {
                var age = "";
                if (!birthday) {
                    return age;
                }
                var r = birthday.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
                if (!r) return age;
                var d = new Date(r[1], r[3] - 1, r[4]);
                if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]) {
                    var Y = new Date().getFullYear();
                    age = (Y - r[1]) + "岁"
                }
                return age;
            },
            GetAgeByIdCard(idcard) {
                if (!idcard) {
                    return "";
                }
                //获取年龄
                var myDate = new Date();
                var month = myDate.getMonth() + 1;
                var day = myDate.getDate();
                var age = myDate.getFullYear() - idcard.substring(6, 10) - 1;
                if (idcard.substring(10, 12) < month || idcard.substring(10, 12) == month && idcard.substring(12, 14) <=
                    day) {
                    age++;
                }
                return age + "岁";
            },
            GetBirthDayByIdCard(idcard) {
                if (!idcard) {
                    return "";
                }
                //获取身份证号的年、月、日
                var year = idcard.substring(6, 10);
                var month = idcard.substring(10, 12);
                var day = idcard.substring(12, 14);
                //拼接成出生日期
                var birthDate = year + '-' + month + '-' + day;
                return birthDate;
            }
        }

        /*
        * 入口
        */
        controller.init();
    });

</script>

<div id="imgPreview" class="imgPreview" style="display:none">
    <div class="imgtop" id="imgtop">
        <div class="btndiv" id="beforImg">
            <a href="#">
                <img style="height:38px;width:38px" src="~/resource/leftJT.png" />
            </a>
        </div>

        <div class="btndiv" id="rotateleft">
            <a href="#">
                <img src="~/resource/turnleft.png" />
            </a>

        </div>
        <div class="btndiv" id="rotatergt">
            <a href="#">
                <img src="~/resource/turnrgt.png" />
            </a>

        </div>
        <div class="btndiv" id="bigit">
            <a href="#">
                <img src="~/resource/bigit.png" />
            </a>

        </div>
        <div class="btndiv" id="littleit">
            <a href="#">
                <img src="~/resource/littleit.png" />
            </a>

        </div>
        <div class="btndiv" id="nextImg">
            <a href="#">
                <img style="height:38px;width:38px" src="~/resource/rightJT.png" />
            </a>
        </div>
    </div>
    <div class="imgcont" id="imgdiv">
        <img src="" mode="aspectFit" id="targetimg" />
    </div>
</div>
<script id="fileOCRTemp" type="text/html">
    {{# if(d.model){ }}
    <div class="ocrContent">
        <div class="ocrImgDiv" name="ocrImgDiv" id="ocrImgDiv"><image src="{{d.model.FileUrl}}" class="ocrImg"></image></div>
        {{# if(d.model.IsSuccess==0){ }}
        <div style="color:red">识别失败</div>
        <div>{{d.model.ErrorText}}</div>
        {{#  }else{ }}
        <div class="ocrtxt">
            <ul>
                {{#  layui.each(d.model.list, function(index, item){ }}
                <li style="font-size:16px;padding:5px;border:1px solid #eeeeee">
                    {{item.Text}}
                </li>
                {{#  }) }}
            </ul>
        </div>
        {{#  } }}
        {{# if(d.Count>1){ }}
        <div class="ocrtips">
            <text class="nexttxt" data-index="0">上一张</text>
            <text class="nexttxt" data-index="1">下一张</text>
        </div>
        {{#  } }}
    </div>
    {{#  } }}
</script>
<script id="shyjTem" type="text/html">
    {{# if(d.AuditStatus>1){ }}
    <div class="title" style="padding-top:10px">资料审核</div>
    <div class="right-row" style="padding-top: 0px">
        <div class="right-row-lab" style="padding-top:10px">
            {{# if(d.AuditStatus==2){ }}
            <span style="color:blue"> 审核通过</span>
            {{#  } }}
            {{# if(d.AuditStatus==3){ }}
            <span style="color:red"> 审核不通过</span>
            {{#  } }}
        </div>

    </div>
    <div class="right-row-input" style="padding-top:10px">
        {{d.AuditTxt}}
    </div>
    {{#  } }}
</script>


<script id="fileTemp" type="text/html">
    {{# if(d.model.Type==1){ }}
    {{#  layui.each(d.list, function(index, item){ }}
    <div>
        {{index+1}}、{{item.QTitle}}
    </div>
    <div style="padding-left:25px">{{item.ATitle}}</div>
    {{#  }) }}
    {{# if(!d.list||d.list.length==0){ }}
    <div>暂无</div>

    {{#  } }}
    {{#  }else if(d.model.Type==2){ }}
    <div>图片:</div>
    <div class="imgflex">
        {{#  layui.each(d.list, function(index, item){ }}
        {{# if(item.Type==0){ }}
        <image class="img" data-index="{{index}}" data-type="{{item.Type}}" src="{{item.FileUrl}}" />
        {{#  } }}
        {{#  }) }}
    </div>
    <div>视频:</div>
    <div class="imgflex">
        <div style="position:relative;"></div>
        {{#  layui.each(d.list, function(index, item){ }}
        {{# if(item.Type==1){ }}
        <div style="position:relative;">
            <image class="img" src="{{item.FileUrl}}?x-oss-process=video/snapshot,t_0,f_jpg" />
            <div class="bofang img" data-index="{{index}}" data-type="{{item.Type}}" data-fileurl="{{item.FileUrl}}">
                <image data-index="{{index}}" data-type="{{item.Type}}" data-fileurl="{{item.FileUrl}}" style="width: 40px;height: 40px; margin: 20px 0 0 20px;" src="/resource/play2.png"></image>
            </div>
        </div>
        {{#  } }}
        {{#  }) }}
    </div>
    {{# if(!d.list||d.list.length==0){ }}
    <div>暂无</div>
    {{#  } }}
    {{#  }else if(d.model.Type==3){ }}
    <div class="imgflex">
        {{#  layui.each(d.list, function(index, item){ }}
        <image class="img" data-index="{{index}}" src="{{item.FileUrl}}" />
        {{#  }) }}
    </div>
    <div>{{d.model.TxtValue}} </div>
    {{#  } }}
</script>

<script id="fileHeadTemp" type="text/html">
    <ul>
        {{#  layui.each(d.data, function(index, item){ }}
        <li data-index="{{index}}" class="{{index==d.currentIndex?'sele':''}}">
            <i class="layui-icon layui-icon-read"></i>
            {{# if(item.Type==2||item.Type==3){ }}
            <span>{{item.FileName}}({{item.Count}})</span>
            {{#  }else{ }}
            <span>{{item.FileName}}</span>
            {{#  } }}
        </li>
        {{#  }) }}
    </ul>
</script>
<script id="diagnosTemp" type="text/html">
    <ul class="layui-tab-title" id="ulservicelabel">
        {{#  layui.each(d, function(index, item){ }}
        <li>
            <span>{{item.DiagnosisName}}</span>
        </li>
        {{#  }) }}
    </ul>
</script>

<script id="patInfoTemp" type="text/html">
    <div class="title">用户资料详情</div>
    <div class="user-info">
        <div class="user-lab">
            <div>患者姓名：</div>
            <div>{{d.PatName}}</div>
        </div>
        <div class="user-lab">
            <div>性别：</div>
            <div>{{d.Sex==1?'男':'女'}}</div>
        </div>
        <div class="user-lab">
            <div>年龄：</div>
            <div>{{d.Age}}</div>
        </div>
        <div class="user-lab">
            <div>出生日期：</div>
            <div>{{d.BirthDay}}</div>
        </div>
        <div class="user-lab">
            <div>联系电话：</div>
            <div>{{d.Phone||''}}</div>
        </div>
        <div class="user-lab">
            <div>身高：</div>
            <div>{{d.Height||''}}cm</div>
        </div>
        <div class="user-lab">
            <div>体重：</div>
            <div>{{d.Weight||''}}kg</div>
        </div>
        <div class="user-lab">
            <div>BMI：</div>
            <div>{{d.BMI||''}}</div>
        </div>
    </div>
    <div class="line"></div>
    <div class="tabsel" id="tabsel">
        <div class="tabselDiv seldiv" data-index="0">复诊资料(图片)</div>
        <div class="tabselDiv" data-index="1">复诊资料(OCR)</div>
    </div>
</script>

<script id="patMedInfoTemp" type="text/html">
    <div class="title">病历资料</div>
    <div class="user-info">
        <div class="user-lab">
            <div>患者姓名：</div>
            <div>{{d.PatName}}</div>
        </div>
        <div class="user-lab">
            <div>性别：</div>
            <div>{{d.Sex==1?'男':'女'}}</div>
        </div>
        <div class="user-lab">
            <div>年龄：</div>
            <div>{{d.Age}}</div>
        </div>
        <div class="user-lab">
            <div>科室：</div>
            <div>{{d.DeptName}}</div>
        </div>
        <div class="user-lab">
            <div>复诊日期：</div>
            <div>{{d.FurtherDate.substr(0,10)}}</div>
        </div>
    </div>
    <div class="right-row">
        <div class="right-row-lab">过敏史：</div>
        <div class="right-row-input">{{d.Allergies||''}}</div>
    </div>
</script>